1. Field of the Invention
This invention relates generally to computer operating systems. More particularly, the invention relates to a system and method for ensuring that a software application designed to operate in a cooperative scheduling environment operates correctly in a preemptive task scheduling environment.
2. Description of Background Art
Designers of operating systems incorporate a wide variety of functions into their design. Process scheduling is one such operating system function. Operating systems define a process scheduling environment. Examples of process scheduling environments include a cooperative scheduling environment and a preemptive task scheduling environment.
In a cooperative scheduling environment, software applications are scheduled cooperatively. That is, once a first cooperative application begins executing, no other cooperative application may execute until either: (1) the first cooperative application explicitly relinquishes control of the central processing unit (CPU); or (2) a cooperative interrupt occurs. An application is a procedure, e.g., a program, that is designed to operate in a cooperative scheduling environment while a task is a procedure designed to operate in any other operating system environment, e.g., the preemptive task scheduling environment.
During execution, applications can initiate asynchronous operations, i.e., operations that will complete at a later time. Examples of asynchronous operations include an input/output (I/O) operation or the setting of a timer. When the asynchronous operation is complete, e.g., the I/O transfer is complete or the specified time has elapsed, a cooperative interrupt is generated. Completion information is sent to the interrupt handling routine associated with the source application, i.e., the application initiating the asynchronous operation. The completion information identifies the associated asynchronous request. The appropriate interrupt handler within the source application, interrupts the current cooperative application (CCA), i.e., the application currently executing. The current cooperative application is interrupted even if it is not the source application. In response to the interrupt, the CPU executes the interrupt completion routine.
After the completion routine has finished executing, the operating system determines if any other cooperative interrupts are pending. If additional cooperative interrupts are pending, these interrupts are serviced, i.e., the appropriate completion routine is executed. When no more cooperative interrupts are pending, the current cooperative application continues execution.
In the cooperative scheduling environment, an application can ensure that it will not be interrupted by disabling all cooperative interrupts. An application may disable the cooperative interrupts if it is executing a function that, for example, must be completed before it can properly service the asynchronous operation. To effectuate this, all applications in the cooperative scheduling environment have the ability to disable all cooperative interrupts.
An example of a cooperative scheduling environment is an Apple System 7 operating system for the Macintosh Computer, commercially available from Apple Computer, Inc., Cupertino, Calif.
A second type of scheduling environment is a preemptive task scheduling environment. Examples of a preemptive task scheduling environment include UNIX System V, developed by AT&T Bell Laboratories, and Windows NT, developed by Microsoft Corporation. In a preemptive task scheduling environment the operating system kernel controls which task has access to the CPU. That is, a task operating in a preemptive task scheduling environment may have its CPU access taken away by the operating system kernel. This is in contrast to the cooperative scheduling environment, where CPU access is controlled by the applications.
A feature of a preemptive task scheduling environment is that if a first task is unable to execute for any reason, e.g., if a page fault occurs, the kernel will suspend execution of the first task and a second task can begin execution. In contrast, if an application that is executing in a cooperative scheduling environment is similarly unable to run, no other application can execute because the current cooperative application cannot be forced to relinquish control of the CPU.
Another feature of preemptive task scheduling environments is that non-operating system tasks and applications are generally not executed in privileged mode or at a hardware interrupt level. In contrast, cooperative applications are frequently designed to execute in privileged mode or at a hardware interrupt level. In addition, cooperative applications are frequently designed based upon, and their proper operation relies upon, the interrupt semantics of the cooperative scheduling environment. Such interrupt semantics include a restriction that no application may execute while the interrupt completion routine executes, and that a single operation can disable interrupts for all applications. These cooperative interrupt semantics are not present in conventional preemptive task scheduling environments
The above discussion demonstrates some of the difficulties involved in attempting to execute cooperative applications in a preemptive task scheduling environment. The Apple A/UX Unix operating system, developed and commercially distributed by Apple Computer, Inc., Cupertino, Calif., attempted to permit execution of cooperative applications in a preemptive task scheduling environment. However, the A/UX does not address the above mentioned compatibility problems. Specifically, the A/UX system did not preserve the time sequence, i.e., the ordering, in which the cooperative interrupts are delivered to different applications.
The A/UX system executes each interrupt handler via a Unix "signal" operation directed to the source application. Thereafter, the source application executes the interrupt completion routine. This design requires a complex application/task scheduler that requires frequent access to the operating system kernel, thereby decreasing the performance of the operating system.
When an interrupt signal is delivered to an application in the A/UX system, the kernel must prevent interrupts from executing in all other applications. Therefore, the delivery of a single interrupt affects the scheduling of all other applications. Rescheduling all of the applications further decreases the performance of the A/UX operating system.
Another compatibility problem arises when an application is written in a machine language of an instruction set architecture that differs from the machine language of an instruction set architecture of the preemptive task scheduling environment. The A/UX system does not address this problem.
What is needed is a system and method for: (1) executing applications written in a cooperative scheduling environment in a preemptive task scheduling environment; (2) ensuring that the time sequence for the delivery of interrupts is not altered in the preemptive task scheduling environment; (3) efficiently disabling all cooperative interrupts in response to a request from an application; (4) efficiently scheduling all cooperative interrupts; and (5) efficiently executing emulated instructions while preserving the integrity, i.e., the atomicity, of the emulated instructions.